export default {
	data() {
		return {
			//数据
      validate: {}, //验证对象
      newsRelease: {} //新闻信息
		}
	},
	created() { //调用方法
	},
	mounted() {
    let that = this;
	  UE.delEditor('editor');
		var ue = UE.getEditor('editor');

    //加载表单验证
    that.validate = $("#newsReleaseForm").validate({
      ignore: [],
      rules: {
        name: { // 新闻发布名称
          required: true,
          maxlength: 100
        },
        content: { // 新闻发布内容
          required: true,
          maxlength: 200
        }
      },
      messages: {
        name: { // 新闻发布名称
          required: "请输入新闻发布标题",
          maxlength: "请输入长度小于100"
        },
        content: { // 新闻发布内容
          required: "请输入主要任务",
          maxlength: "请输入长度小于200"
        }
      },
      errorElement: "em",
      errorPlacement: function (error, element) {
        error.appendTo(element.parents(".error-box").children(".error-msg"));
      }
    });
	},
	methods: { //写函数方法
    //保存并发布
	  saveAndRelease: function () {
      let that = this;
      let flg = that.validate.form();
      if (flg) {
        let dataObj = that.combinationFormObject(that.validate.currentForm);
        dataObj["releaseStatus"] = 1;
        that.$post(
          that.urls.addNewsRelease,
          dataObj
        )
        .then(function(res) {
          let msg = "";
          if(res.success) {
            msg = "保存并发布文本新闻成功！";
          } else {
            msg = "保存并发布文本新闻失败！";
          }
          layer.msg(msg, {
            time: 3000, //3s后自动关闭
          });
        })
      }
    }
	}
}
